<!Doctype html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<title>Python 变量类型 | 菜鸟教程</title>

  <meta name='robots' content='max-image-preview:large' />
<link rel='stylesheet' id='classic-theme-styles-css' href='../0/classic-themes.min.css?ver=6.2' type='text/css' media='all' />
<link rel="canonical" href="../python/python-variable-types.html" />
<meta name="keywords" content="Python 变量类型">
<meta name="description" content="Python 变量类型  变量是存储在内存中的值，这就意味着在创建变量时会在内存中开辟一个空间。 基于变量的数据类型，解释器会分配指定内存，并决定什么数据可以被存储在内存中。 因此，变量可以指定不同的数据类型，这些变量可以存储整数，小数或字符。   变量赋值 Python 中的变量赋值不需要类型声明。 每个变量在内存中创建，都包括变量的标识，名称和数据这些信息。 每个变量在使用前都必须赋值，变量赋值以后该变量才会被创建。 等号 = 用来..">
		
	<link rel="shortcut icon" href="https://static.runoob.com/images/favicon.ico">
	<link rel="stylesheet" href="../0/style.css?v=1.170" type="text/css" media="all" />	
	<link rel="stylesheet" href="../0/font-awesome.min.css" media="all" />	
  <!--[if gte IE 9]><!-->
  <script src=""></script>
  <!--<![endif]-->
  <!--[if lt IE 9]>
     <script src=""></script>
     <script src=""></script>
  <![endif]-->
  <link rel="apple-touch-icon" href="https://static.runoob.com/images/icon/mobile-icon.png"/>
  <meta name="apple-mobile-web-app-title" content="菜鸟教程">
</head>
<body>

<!--  头部 -->
<div class="container logo-search">

  <div class="col search row-search-mobile">
    <form action="index.php">
      <input class="placeholder" placeholder="搜索……" name="s" autocomplete="off">
      
    </form>
  </div>

  <div class="row">
    <div class="col logo">
      <h1><a href="../">菜鸟教程 -- 学的不仅是技术，更是梦想！</a></h1>
    </div>
        <div class="col right-list"> 
    <button class="btn btn-responsive-nav btn-inverse" data-toggle="collapse" data-target=".nav-main-collapse" id="pull" style=""> <i class="fa fa-navicon"></i> </button>
    </div>
        
    <div class="col search search-desktop last">
      <div class="search-input" >
      <form action="//www.runoob.com/" target="_blank">
        <input class="placeholder" id="s" name="s" placeholder="搜索……"  autocomplete="off" style="height: 44px;">
      </form>
      
      </div>
    </div>
  </div>
</div>



<!-- 导航栏 -->
<!-- 导航栏 -->
<div class="container navigation">
	<div class="row">
		<div class="col nav">
			<ul class="pc-nav" id="runoob-detail-nav">
				<li><a href="../">首页</a></li>
				<li><a href="../html/html-tutorial.html">HTML</a></li>
				<li><a href="../css/css-tutorial.html">CSS</a></li>
				<li><a href="../js/js-tutorial.html">JavaScript</a></li>
				<li><a href="javascript:void(0);" data-id="vue">Vue</a></li>
				<li><a href="javascript:void(0);" data-id="bootstrap">Bootstrap</a></li>
				<li><a href="../nodejs/nodejs-tutorial.html">NodeJS</a></li>
				<li><a href="../python3/python3-tutorial.html">Python3</a></li>
				<li><a href="../python/python-tutorial.html">Python2</a></li>
				<li><a href="../java/java-tutorial.html">Java</a></li>
				<li><a href="../cprogramming/c-tutorial.html">C</a></li>
				<li><a href="../cplusplus/cpp-tutorial.html">C++</a></li>
				<li><a href="../csharp/csharp-tutorial.html">C#</a></li>
				<li><a href="../go/go-tutorial.html">Go</a></li>
				<li><a href="../sql/sql-tutorial.html">SQL</a></li>
				<li><a href="../linux/linux-tutorial.html">Linux</a></li>
				<li><a href="../jquery/jquery-tutorial.html">jQuery</a></li>
				<li><a href="../browser-history">本地书签</a></li>
				<!--
			
				<li><a href="../w3cnote/knowledge-start.html" style="font-weight: bold;" onclick="_hmt.push(['_trackEvent', '星球', 'click', 'start'])" title="我的圈子">我的圈子</a></li>				
				<li><a href="javascript:;" class="runoob-pop">登录</a></li>
				-->
      		</ul>
			<ul class="mobile-nav">
				<li><a href="../">首页</a></li>
				<li><a href="../html/html-tutorial.html">HTML</a></li>
				<li><a href="../css/css-tutorial.html">CSS</a></li>
				<li><a href="../js/js-tutorial.html">JS</a></li>
				<li><a href="../browser-history">本地书签</a></li>
				<li><a href="javascript:void(0)" class="search-reveal">Search</a> </li>
			</ul>
			
		</div>
	</div>
</div>

<div class="container sub-navigation sub-navigation-articles" style="display:none">
	<div class="row">
		<div class="col nav-sub">
		<ul id="python">
			<li class="cat-item"><a href="../python3/python3-tutorial.html">Python3 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../python/python-tutorial.html">Python2 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
		</ul>
		<ul id="vue">
			<li class="cat-item"><a href="../vue3/vue3-tutorial.html">Vue3 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../vue/vue-tutorial.html">vue2 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
		</ul>

		<ul id="bootstrap">
			<li class="cat-item"><a href="../bootstrap/bootstrap-tutorial.html">Bootstrap3 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../bootstrap4/bootstrap4-tutorial.html">Bootstrap4 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../bootstrap5/bootstrap5-tutorial.html">Bootstrap5 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../bootstrap/bootstrap-v2-tutorial.html">Bootstrap2 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
		</ul>
		</div>
	</div>
</div><!--  内容  -->
<div class="container main">
	<!-- 中间 -->
	<div class="row">
	
<div class="runoob-col-md2">
<div class="left-column">
	<div class="tab" style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">
	<i class="fa fa-list" aria-hidden="true"></i> 
	<span>Python 基础教程</span>
	<a data-cate="48" href="javascript:void(0);" title="夜间模式"  id="moon"><i class="fa fa-moon-o" aria-hidden="true" style="line-height: 28px;font-size: 1.2em;margin: 2px 4px 0;"></i></a>
	<a data-cate="48" style="display:none;" href="javascript:void(0);" title="日间模式"  id="sun" ><i class="fa fa-sun-o" aria-hidden="true" style="line-height: 28px;font-size: 1.2em;margin: 2px 4px 0;line-height: 28px;
}"></i></a>

	</div>
	<div class="sidebar-box gallery-list">
		<div class="design" id="leftcolumn">
						<a target="_top" title="Python 基础教程"  href="../python/python-tutorial.html" >
			Python 基础教程			</a>
						<a target="_top" title="Python 简介"  href="../python/python-intro.html" >
			Python 简介			</a>
						<a target="_top" title="Python 环境搭建"  href="../python/python-install.html" >
			Python 环境搭建			</a>
			<a target="_top" title="Python 中文编码" href="python-chinese-encoding.html"> Python 中文编码 </a>			<a target="_top" title="Python 基础语法"  href="../python/python-basic-syntax.html" >
			Python 基础语法			</a>
						<a target="_top" title="Python 变量类型"  href="../python/python-variable-types.html" >
			Python 变量类型			</a>
						<a target="_top" title="Python 运算符"  href="../python/python-operators.html" >
			Python 运算符			</a>
						<a target="_top" title="Python 条件语句"  href="../python/python-if-statement.html" >
			Python 条件语句			</a>
						<a target="_top" title="Python 循环语句"  href="../python/python-loops.html" >
			Python 循环语句			</a>
						<a target="_top" title="Python While 循环语句"  href="../python/python-while-loop.html" >
			Python While 循环语句			</a>
						<a target="_top" title="Python for 循环语句"  href="../python/python-for-loop.html" >
			Python for 循环语句			</a>
						<a target="_top" title="Python 循环嵌套"  href="../python/python-nested-loops.html" >
			Python 循环嵌套			</a>
						<a target="_top" title="Python break 语句"  href="../python/python-break-statement.html" >
			Python break 语句			</a>
						<a target="_top" title="Python continue  语句"  href="../python/python-continue-statement.html" >
			Python continue  语句			</a>
						<a target="_top" title="Python pass 语句"  href="../python/python-pass-statement.html" >
			Python pass 语句			</a>
						<a target="_top" title="Python Number(数字)"  href="../python/python-numbers.html" >
			Python Number(数字)			</a>
						<a target="_top" title="Python 字符串"  href="../python/python-strings.html" >
			Python 字符串			</a>
						<a target="_top" title="Python 列表(List)"  href="../python/python-lists.html" >
			Python 列表(List)			</a>
						<a target="_top" title="Python 元组"  href="../python/python-tuples.html" >
			Python 元组			</a>
						<a target="_top" title="Python 字典(Dictionary)"  href="../python/python-dictionary.html" >
			Python 字典(Dictionary)			</a>
						<a target="_top" title="Python 日期和时间"  href="../python/python-date-time.html" >
			Python 日期和时间			</a>
						<a target="_top" title="Python 函数"  href="../python/python-functions.html" >
			Python 函数			</a>
						<a target="_top" title="Python 模块"  href="../python/python-modules.html" >
			Python 模块			</a>
						<a target="_top" title="Python 文件I/O"  href="../python/python-files-io.html" >
			Python 文件I/O			</a>
			<a target="_top" title="Python File 方法" href="file-methods.html">Python File 方法</a>			<a target="_top" title="Python 异常处理"  href="../python/python-exceptions.html" >
			Python 异常处理			</a>
			<a target="_top" title="Python OS 文件/目录方法" href="os-file-methods.html">Python OS 文件/目录方法</a>
<a target="_top" title="Python 内置函数" href="python-built-in-functions.html">Python 内置函数</a>
<br><h2 class="left"><span class="left_h2">Python</span> 高级教程</h2>			<a target="_top" title="Python 面向对象"  href="../python/python-object.html" >
			Python 面向对象			</a>
						<a target="_top" title="Python 正则表达式"  href="../python/python-reg-expressions.html" >
			Python 正则表达式			</a>
						<a target="_top" title="Python CGI 编程"  href="../python/python-cgi.html" >
			Python CGI 编程			</a>
						<a target="_top" title="Python 操作 MySQL 数据库"  href="../python/python-mysql.html" >
			Python MySQL			</a>
			<a target="_top" title="Python 网络编程" href="python-socket.html"> Python 网络编程 </a>			<a target="_top" title="Python SMTP发送邮件"  href="../python/python-email.html" >
			Python SMTP			</a>
						<a target="_top" title="Python 多线程"  href="../python/python-multithreading.html" >
			Python 多线程			</a>
						<a target="_top" title="Python XML 解析"  href="../python/python-xml.html" >
			Python XML 解析			</a>
						<a target="_top" title="Python GUI 编程(Tkinter)"  href="../python/python-gui-tkinter.html" >
			Python GUI 编程(Tkinter)			</a>
						<a target="_top" title="Python2.x 与 3​​.x 版本区别"  href="../python/python-2x-3x.html" >
			Python2.x 与 3​​.x 版本区别			</a>
						<a target="_top" title="Python IDE"  href="../python/python-ide.html" >
			Python IDE			</a>
						<a target="_top" title="Python JSON"  href="../python/python-json.html" >
			Python JSON			</a>
			<a target="_blank" title="Python AI 绘画" href="../python3/python-ai-draw.html">Python AI 绘画			</a>			<a target="_top" title="Python 100例"  href="../python/python-100-examples.html" >
			Python 100例			</a>
			<a target="_blank" title="Python 测验" href="../quiz/python-quiz.html"> Python 测验 </a>	
		</div>
	</div>	
</div>
</div>	<div class="col middle-column">
		
	
	<div class="article">
		
		<div class="previous-next-links">
			<div class="previous-design-link"><i style="font-size:16px;" class="fa fa-arrow-left" aria-hidden="true"></i> <a href="../python/python-basic-syntax.html" rel="prev"> Python 基础语法</a> </div>
			<div class="next-design-link"><a href="../python/python-operators.html" rel="next"> Python 运算符</a> <i style="font-size:16px;" class="fa fa-arrow-right" aria-hidden="true"></i></div>
		</div>
<div class="article-heading-ad" style="display: block;">
<script async src=""
     crossorigin="anonymous"></script>
<!-- 728*90 固定 -->
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-5751451760833794"
     data-ad-slot="2147566827"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
		</div>
		<div class="article-body">
		
			<div class="article-intro" id="content">
			
			<h1>Python <span class="color_h1">变量类型</span></h1>
<div class="tutintro">
<p>变量是存储在内存中的值，这就意味着在创建变量时会在内存中开辟一个空间。</p>
<p>基于变量的数据类型，解释器会分配指定内存，并决定什么数据可以被存储在内存中。</p>
<p>因此，变量可以指定不同的数据类型，这些变量可以存储整数，小数或字符。</p>
</div>

<br><hr><h2>变量赋值</h2>
<p>Python 中的变量赋值不需要类型声明。</p>
<p>每个变量在内存中创建，都包括变量的标识，名称和数据这些信息。</p>
<p>每个变量在使用前都必须赋值，变量赋值以后该变量才会被创建。</p>
<p>等号 <span class="marked">=</span> 用来给变量赋值。</p>
<p>等号 <span class="marked">=</span> 运算符左边是一个变量名，等号 <span class="marked">=</span> 运算符右边是存储在变量中的值。例如：</p>
<div class="example"> 
<h2 class="example">实例(Python 2.0+)</h2> 
<div class="example_code">
<div class="hl-main"><span class="hl-comment">#!/usr/bin/python</span><span class="hl-code">
</span><span class="hl-comment"># -*- coding: UTF-8 -*-</span><span class="hl-code">
 
</span><span class="hl-identifier">counter</span><span class="hl-code"> = </span><span class="hl-number">100</span><span class="hl-code"> </span><span class="hl-comment"># 赋值整型变量</span><span class="hl-code">
</span><span class="hl-identifier">miles</span><span class="hl-code"> = </span><span class="hl-number">1000.0</span><span class="hl-code"> </span><span class="hl-comment"># 浮点型</span><span class="hl-code">
</span><span class="hl-identifier">name</span><span class="hl-code"> = </span><span class="hl-quotes">&quot;</span><span class="hl-string">John</span><span class="hl-quotes">&quot;</span><span class="hl-code"> </span><span class="hl-comment"># 字符串</span><span class="hl-code">
 
</span><span class="hl-reserved">print</span><span class="hl-code"> </span><span class="hl-identifier">counter</span><span class="hl-code">
</span><span class="hl-reserved">print</span><span class="hl-code"> </span><span class="hl-identifier">miles</span><span class="hl-code">
</span><span class="hl-reserved">print</span><span class="hl-code"> </span><span class="hl-identifier">name</span></div>
</div>
<br>
<a href="../try/runcode.php?filename=demo_variable&type=python" target="_blank" class="tryitbtn" rel="noopener noreferrer">运行实例 »</a>
</div>


<p>以上实例中，100，1000.0和"John"分别赋值给counter，miles，name变量。</p>
<p>执行以上程序会输出如下结果：</p>
<pre>
100
1000.0
John
</pre>

<br><hr><h2>多个变量赋值</h2>
<p>Python允许你同时为多个变量赋值。例如：</p>

<pre>a = b = c = 1</pre>

<p>以上实例，创建一个整型对象，值为1，三个变量被分配到相同的内存空间上。</p>

<p>您也可以为多个对象指定多个变量。例如：</p>

<pre>a, b, c = 1, 2, "john"</pre>

<p>以上实例，两个整型对象 1 和 2 分别分配给变量 a 和 b，字符串对象 "john" 分配给变量 c。</p>
<br><hr><h2>标准数据类型</h2>
<p>在内存中存储的数据可以有多种类型。</p>
<p>例如，一个人的年龄可以用数字来存储，他的名字可以用字符来存储。</p>
<p>Python 定义了一些标准类型，用于存储各种类型的数据。</p>
<p>Python有五个标准的数据类型：</p>
<ul>
<li>Numbers（数字）</li>
<li>String（字符串）</li>
<li>List（列表）</li>
<li>Tuple（元组）</li>
<li>Dictionary（字典）</li>
</ul>

<br><hr><h2>Python 数字</h2>
<p>数字数据类型用于存储数值。</p>
<p>他们是不可改变的数据类型，这意味着改变数字数据类型会分配一个新的对象。</p>
<p>当你指定一个值时，Number 对象就会被创建：</p>
<pre>var1 = 1
var2 = 10</pre>
<p>您也可以使用del语句删除一些对象的引用。</p>
<p> del语句的语法是：</p>

<pre>del var1[,var2[,var3[....,varN]]]</pre>

<p>您可以通过使用del语句删除单个或多个对象的引用。例如：</p>
<pre>del var
del var_a, var_b</pre>
<p>Python支持四种不同的数字类型：</p>
<ul>
<li>int（有符号整型）</li>
<li>long（长整型，也可以代表八进制和十六进制）	</li>	<li>		float（浮点型）	</li>	<li>		complex（复数）	</li></ul>

<strong>实例</strong>
<p>一些数值类型的实例：</p>
<table class="reference">
<tbody><tr><th>int</th><th>long</th><th>float</th><th>complex</th></tr>
<tr><td>10</td><td>51924361L</td><td>0.0</td><td>3.14j</td></tr>
<tr><td>100</td><td>-0x19323L</td><td>15.20</td><td>45.j</td></tr>
<tr><td>-786</td><td>0122L</td><td>-21.9</td><td>9.322e-36j</td></tr>
<tr><td>080</td><td>0xDEFABCECBDAECBFBAEl</td><td>32.3e+18</td><td>.876j</td></tr>
<tr><td>-0490</td><td>535633629843L</td><td>-90.</td><td>-.6545+0J</td></tr>
<tr><td>-0x260</td><td>-052318172735L</td><td>-32.54e100</td><td>3e+26J</td></tr>
<tr><td>0x69</td><td>-4721885298529L</td><td>70.2E-12</td><td>4.53e-7j</td></tr>
</tbody></table>

<ul>
<li>长整型也可以使用小写 l，但是还是建议您使用大写 L，避免与数字 1 混淆。Python使用 L 来显示长整型。</li>
<li>Python 还支持复数，复数由实数部分和虚数部分构成，可以用 a + bj,或者 complex(a,b) 表示，
复数的实部 a 和虚部 b 都是浮点型。
</li>
</ul>


<blockquote><p><strong>注意：</strong>long 类型只存在于 Python2.X 版本中，在 2.2 以后的版本中，int 类型数据溢出后会自动转为long类型。在 Python3.X 版本中 long 类型被移除，使用 int 替代。</p></blockquote>


<br><hr><h2>Python字符串</h2>
<p>字符串或串(String)是由数字、字母、下划线组成的一串字符。</p>
<p>一般记为 :</p><pre>s = "a1a2&middot;&middot;&middot;an"   # n&gt;=0</pre>
<p>它是编程语言中表示文本的数据类型。 </p>
<p>python的字串列表有2种取值顺序:</p>
<ul>
<li>从左到右索引默认0开始的，最大范围是字符串长度少1</li>
<li>从右到左索引默认-1开始的，最大范围是字符串开头</li>
</ul>
<p><img decoding="async" src="//www.runoob.com/wp-content/uploads/2013/11/python-string-slice.png"></p>
<p>如果你要实现从字符串中获取一段子字符串的话，可以使用 <span class="marked">[头下标:尾下标]</span> 来截取相应的字符串，其中下标是从 0 开始算起，可以是正数或负数，下标可以为空表示取到头或尾。</p>
<p><span class="marked">[头下标:尾下标]</span> 获取的子字符串包含头下标的字符，但不包含尾下标的字符。</p>
<p>比如:</p>
<pre>
&gt;&gt;&gt; s = 'abcdef'
&gt;&gt;&gt; s[1:5]
'bcde'
</pre>
<p>当使用以冒号分隔的字符串，python 返回一个新的对象，结果包含了以这对偏移标识的连续的内容，左边的开始是包含了下边界。</p>
<p>上面的结果包含了 <span class="marked">s[1]</span> 的值 b，而取到的最大范围不包括<strong>尾下标</strong>，就是 <span class="marked">s[5]</span> 的值 f。</p>

<p><img decoding="async" src="//www.runoob.com/wp-content/uploads/2013/11/o99aU.png"></p>
<p>加号（+）是字符串连接运算符，星号（*）是重复操作。如下实例：</p>
<div class="example"> 
<h2 class="example">实例(Python 2.0+)</h2> 
<div class="example_code">
<div class="hl-main"><span class="hl-comment">#!/usr/bin/python</span><span class="hl-code">
</span><span class="hl-comment"># -*- coding: UTF-8 -*-</span><span class="hl-code">
 
</span><span class="hl-identifier">str</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">Hello World!</span><span class="hl-quotes">'</span><span class="hl-code">
 
</span><span class="hl-reserved">print</span><span class="hl-code"> </span><span class="hl-identifier">str</span><span class="hl-code">           </span><span class="hl-comment"># 输出完整字符串</span><span class="hl-code">
</span><span class="hl-reserved">print</span><span class="hl-code"> </span><span class="hl-identifier">str</span><span class="hl-brackets">[</span><span class="hl-number">0</span><span class="hl-brackets">]</span><span class="hl-code">        </span><span class="hl-comment"># 输出字符串中的第一个字符</span><span class="hl-code">
</span><span class="hl-reserved">print</span><span class="hl-code"> </span><span class="hl-identifier">str</span><span class="hl-brackets">[</span><span class="hl-number">2</span><span class="hl-code">:</span><span class="hl-number">5</span><span class="hl-brackets">]</span><span class="hl-code">      </span><span class="hl-comment"># 输出字符串中第三个至第六个之间的字符串</span><span class="hl-code">
</span><span class="hl-reserved">print</span><span class="hl-code"> </span><span class="hl-identifier">str</span><span class="hl-brackets">[</span><span class="hl-number">2</span><span class="hl-code">:</span><span class="hl-brackets">]</span><span class="hl-code">       </span><span class="hl-comment"># 输出从第三个字符开始的字符串</span><span class="hl-code">
</span><span class="hl-reserved">print</span><span class="hl-code"> </span><span class="hl-identifier">str</span><span class="hl-code"> * </span><span class="hl-number">2</span><span class="hl-code">       </span><span class="hl-comment"># 输出字符串两次</span><span class="hl-code">
</span><span class="hl-reserved">print</span><span class="hl-code"> </span><span class="hl-identifier">str</span><span class="hl-code"> + </span><span class="hl-quotes">&quot;</span><span class="hl-string">TEST</span><span class="hl-quotes">&quot;</span><span class="hl-code">  </span><span class="hl-comment"># 输出连接的字符串</span></div>
</div>
</div>
<p>以上实例输出结果：</p>
<pre>
Hello World!
H
llo
llo World!
Hello World!Hello World!
Hello World!TEST
</pre>

<p>Python 列表截取可以接收第三个参数，参数作用是截取的步长，以下实例在索引 1 到索引 4 的位置并设置为步长为 2（间隔一个位置）来截取字符串：</p>
<p><img decoding="async" src="//www.runoob.com/wp-content/uploads/2013/11/python_list_slice_2.png"></p>
<br><hr><h2>Python列表</h2>
<p>List（列表） 是 Python 中使用最频繁的数据类型。</p>
<p>列表可以完成大多数集合类的数据结构实现。它支持字符，数字，字符串甚至可以包含列表（即嵌套）。</p>
<p>列表用 <span class="marked">[ ]</span> 标识，是 python 最通用的复合数据类型。</p>
<p>列表中值的切割也可以用到变量 <span class="marked">[头下标:尾下标]</span> ，就可以截取相应的列表，从左到右索引默认 0 开始，从右到左索引默认 -1 开始，下标可以为空表示取到头或尾。</p>
<p><img decoding="async" src="https://www.runoob.com/wp-content/uploads/2014/08/list_slicing1_new1.png"></p>
<p>加号 <span class="marked">+</span> 是列表连接运算符，星号 <span class="marked">*</span> 是重复操作。如下实例：</p>
<div class="example"> 
<h2 class="example">实例(Python 2.0+)</h2> 
<div class="example_code">
<div class="hl-main"><span class="hl-comment">#!/usr/bin/python</span><span class="hl-code">
</span><span class="hl-comment"># -*- coding: UTF-8 -*-</span><span class="hl-code">
 
</span><span class="hl-identifier">list</span><span class="hl-code"> = </span><span class="hl-brackets">[</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">runoob</span><span class="hl-quotes">'</span><span class="hl-code">, </span><span class="hl-number">786</span><span class="hl-code"> , </span><span class="hl-number">2.23</span><span class="hl-code">, </span><span class="hl-quotes">'</span><span class="hl-string">john</span><span class="hl-quotes">'</span><span class="hl-code">, </span><span class="hl-number">70.2</span><span class="hl-code"> </span><span class="hl-brackets">]</span><span class="hl-code">
</span><span class="hl-identifier">tinylist</span><span class="hl-code"> = </span><span class="hl-brackets">[</span><span class="hl-number">123</span><span class="hl-code">, </span><span class="hl-quotes">'</span><span class="hl-string">john</span><span class="hl-quotes">'</span><span class="hl-brackets">]</span><span class="hl-code">
 
</span><span class="hl-reserved">print</span><span class="hl-code"> </span><span class="hl-identifier">list</span><span class="hl-code">               </span><span class="hl-comment"># 输出完整列表</span><span class="hl-code">
</span><span class="hl-reserved">print</span><span class="hl-code"> </span><span class="hl-identifier">list</span><span class="hl-brackets">[</span><span class="hl-number">0</span><span class="hl-brackets">]</span><span class="hl-code">            </span><span class="hl-comment"># 输出列表的第一个元素</span><span class="hl-code">
</span><span class="hl-reserved">print</span><span class="hl-code"> </span><span class="hl-identifier">list</span><span class="hl-brackets">[</span><span class="hl-number">1</span><span class="hl-code">:</span><span class="hl-number">3</span><span class="hl-brackets">]</span><span class="hl-code">          </span><span class="hl-comment"># 输出第二个至第三个元素 </span><span class="hl-code">
</span><span class="hl-reserved">print</span><span class="hl-code"> </span><span class="hl-identifier">list</span><span class="hl-brackets">[</span><span class="hl-number">2</span><span class="hl-code">:</span><span class="hl-brackets">]</span><span class="hl-code">           </span><span class="hl-comment"># 输出从第三个开始至列表末尾的所有元素</span><span class="hl-code">
</span><span class="hl-reserved">print</span><span class="hl-code"> </span><span class="hl-identifier">tinylist</span><span class="hl-code"> * </span><span class="hl-number">2</span><span class="hl-code">       </span><span class="hl-comment"># 输出列表两次</span><span class="hl-code">
</span><span class="hl-reserved">print</span><span class="hl-code"> </span><span class="hl-identifier">list</span><span class="hl-code"> + </span><span class="hl-identifier">tinylist</span><span class="hl-code">    </span><span class="hl-comment"># 打印组合的列表</span></div>
</div>
</div>
<p>以上实例输出结果：<p>
<pre>
['runoob', 786, 2.23, 'john', 70.2]
runoob
[786, 2.23]
[2.23, 'john', 70.2]
[123, 'john', 123, 'john']
['runoob', 786, 2.23, 'john', 70.2, 123, 'john']
</pre>
<br><hr><h2>Python 元组</h2>
<p>元组是另一个数据类型，类似于 List（列表）。</p>
<p>元组用 <span class="marked">()</span>  标识。内部元素用逗号隔开。但是元组不能二次赋值，相当于只读列表。</p>
<div class="example"> 
<h2 class="example">实例(Python 2.0+)</h2> 
<div class="example_code">
<div class="hl-main"><span class="hl-comment">#!/usr/bin/python</span><span class="hl-code">
</span><span class="hl-comment"># -*- coding: UTF-8 -*-</span><span class="hl-code">
 
</span><span class="hl-identifier">tuple</span><span class="hl-code"> = </span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">runoob</span><span class="hl-quotes">'</span><span class="hl-code">, </span><span class="hl-number">786</span><span class="hl-code"> , </span><span class="hl-number">2.23</span><span class="hl-code">, </span><span class="hl-quotes">'</span><span class="hl-string">john</span><span class="hl-quotes">'</span><span class="hl-code">, </span><span class="hl-number">70.2</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">
</span><span class="hl-identifier">tinytuple</span><span class="hl-code"> = </span><span class="hl-brackets">(</span><span class="hl-number">123</span><span class="hl-code">, </span><span class="hl-quotes">'</span><span class="hl-string">john</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">
 
</span><span class="hl-reserved">print</span><span class="hl-code"> </span><span class="hl-identifier">tuple</span><span class="hl-code">               </span><span class="hl-comment"># 输出完整元组</span><span class="hl-code">
</span><span class="hl-reserved">print</span><span class="hl-code"> </span><span class="hl-identifier">tuple</span><span class="hl-brackets">[</span><span class="hl-number">0</span><span class="hl-brackets">]</span><span class="hl-code">            </span><span class="hl-comment"># 输出元组的第一个元素</span><span class="hl-code">
</span><span class="hl-reserved">print</span><span class="hl-code"> </span><span class="hl-identifier">tuple</span><span class="hl-brackets">[</span><span class="hl-number">1</span><span class="hl-code">:</span><span class="hl-number">3</span><span class="hl-brackets">]</span><span class="hl-code">          </span><span class="hl-comment"># 输出第二个至第四个（不包含）的元素 </span><span class="hl-code">
</span><span class="hl-reserved">print</span><span class="hl-code"> </span><span class="hl-identifier">tuple</span><span class="hl-brackets">[</span><span class="hl-number">2</span><span class="hl-code">:</span><span class="hl-brackets">]</span><span class="hl-code">           </span><span class="hl-comment"># 输出从第三个开始至列表末尾的所有元素</span><span class="hl-code">
</span><span class="hl-reserved">print</span><span class="hl-code"> </span><span class="hl-identifier">tinytuple</span><span class="hl-code"> * </span><span class="hl-number">2</span><span class="hl-code">       </span><span class="hl-comment"># 输出元组两次</span><span class="hl-code">
</span><span class="hl-reserved">print</span><span class="hl-code"> </span><span class="hl-identifier">tuple</span><span class="hl-code"> + </span><span class="hl-identifier">tinytuple</span><span class="hl-code">   </span><span class="hl-comment"># 打印组合的元组</span></div>
</div>
</div>
<p>以上实例输出结果：</p>
<pre>
('runoob', 786, 2.23, 'john', 70.2)
runoob
(786, 2.23)
(2.23, 'john', 70.2)
(123, 'john', 123, 'john')
('runoob', 786, 2.23, 'john', 70.2, 123, 'john')
</pre>

<p>以下对元组的操作是无效的，因为元组不允许更新，而列表是允许更新的：</p>
<div class="example"> 
<h2 class="example">实例(Python 2.0+)</h2> 
<div class="example_code">
<div class="hl-main"><span class="hl-comment">#!/usr/bin/python</span><span class="hl-code">
</span><span class="hl-comment"># -*- coding: UTF-8 -*-</span><span class="hl-code">
 
</span><span class="hl-identifier">tuple</span><span class="hl-code"> = </span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">runoob</span><span class="hl-quotes">'</span><span class="hl-code">, </span><span class="hl-number">786</span><span class="hl-code"> , </span><span class="hl-number">2.23</span><span class="hl-code">, </span><span class="hl-quotes">'</span><span class="hl-string">john</span><span class="hl-quotes">'</span><span class="hl-code">, </span><span class="hl-number">70.2</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">
</span><span class="hl-identifier">list</span><span class="hl-code"> = </span><span class="hl-brackets">[</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">runoob</span><span class="hl-quotes">'</span><span class="hl-code">, </span><span class="hl-number">786</span><span class="hl-code"> , </span><span class="hl-number">2.23</span><span class="hl-code">, </span><span class="hl-quotes">'</span><span class="hl-string">john</span><span class="hl-quotes">'</span><span class="hl-code">, </span><span class="hl-number">70.2</span><span class="hl-code"> </span><span class="hl-brackets">]</span><span class="hl-code">
</span><span class="hl-identifier">tuple</span><span class="hl-brackets">[</span><span class="hl-number">2</span><span class="hl-brackets">]</span><span class="hl-code"> = </span><span class="hl-number">1000</span><span class="hl-code">    </span><span class="hl-comment"># 元组中是非法应用</span><span class="hl-code">
</span><span class="hl-identifier">list</span><span class="hl-brackets">[</span><span class="hl-number">2</span><span class="hl-brackets">]</span><span class="hl-code"> = </span><span class="hl-number">1000</span><span class="hl-code">     </span><span class="hl-comment"># 列表中是合法应用</span></div>
<p>元组是不允许更新的，所以以上代码执行错误，结果如下：</p>

<pre>Traceback (most recent call last):
  File "test.py", line 6, in &lt;module&gt;
    tuple[2] = 1000    # 元组中是非法应用
TypeError: 'tuple' object does not support item assignment</pre>
</div>
</div>
<br><hr><h2>Python 字典</h2>
<p>字典(dictionary)是除列表以外python之中最灵活的内置数据结构类型。列表是有序的对象集合，字典是无序的对象集合。
</p><p>两者之间的区别在于：字典当中的元素是通过键来存取的，而不是通过偏移存取。
</p>
<p>字典用"{ }"标识。字典由索引(key)和它对应的值value组成。</p>
<div class="example"> 
<h2 class="example">实例(Python 2.0+)</h2> 
<div class="example_code">
<div class="hl-main"><span class="hl-comment">#!/usr/bin/python</span><span class="hl-code">
</span><span class="hl-comment"># -*- coding: UTF-8 -*-</span><span class="hl-code">
 
</span><span class="hl-identifier">dict</span><span class="hl-code"> = {}
</span><span class="hl-identifier">dict</span><span class="hl-brackets">[</span><span class="hl-quotes">'</span><span class="hl-string">one</span><span class="hl-quotes">'</span><span class="hl-brackets">]</span><span class="hl-code"> = </span><span class="hl-quotes">&quot;</span><span class="hl-string">This is one</span><span class="hl-quotes">&quot;</span><span class="hl-code">
</span><span class="hl-identifier">dict</span><span class="hl-brackets">[</span><span class="hl-number">2</span><span class="hl-brackets">]</span><span class="hl-code"> = </span><span class="hl-quotes">&quot;</span><span class="hl-string">This is two</span><span class="hl-quotes">&quot;</span><span class="hl-code">
 
</span><span class="hl-identifier">tinydict</span><span class="hl-code"> = {</span><span class="hl-quotes">'</span><span class="hl-string">name</span><span class="hl-quotes">'</span><span class="hl-code">: </span><span class="hl-quotes">'</span><span class="hl-string">runoob</span><span class="hl-quotes">'</span><span class="hl-code">,</span><span class="hl-quotes">'</span><span class="hl-string">code</span><span class="hl-quotes">'</span><span class="hl-code">:</span><span class="hl-number">6734</span><span class="hl-code">, </span><span class="hl-quotes">'</span><span class="hl-string">dept</span><span class="hl-quotes">'</span><span class="hl-code">: </span><span class="hl-quotes">'</span><span class="hl-string">sales</span><span class="hl-quotes">'</span><span class="hl-code">}
 
 
</span><span class="hl-reserved">print</span><span class="hl-code"> </span><span class="hl-identifier">dict</span><span class="hl-brackets">[</span><span class="hl-quotes">'</span><span class="hl-string">one</span><span class="hl-quotes">'</span><span class="hl-brackets">]</span><span class="hl-code">          </span><span class="hl-comment"># 输出键为'one' 的值</span><span class="hl-code">
</span><span class="hl-reserved">print</span><span class="hl-code"> </span><span class="hl-identifier">dict</span><span class="hl-brackets">[</span><span class="hl-number">2</span><span class="hl-brackets">]</span><span class="hl-code">              </span><span class="hl-comment"># 输出键为 2 的值</span><span class="hl-code">
</span><span class="hl-reserved">print</span><span class="hl-code"> </span><span class="hl-identifier">tinydict</span><span class="hl-code">             </span><span class="hl-comment"># 输出完整的字典</span><span class="hl-code">
</span><span class="hl-reserved">print</span><span class="hl-code"> </span><span class="hl-identifier">tinydict</span><span class="hl-code">.</span><span class="hl-identifier">keys</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">      </span><span class="hl-comment"># 输出所有键</span><span class="hl-code">
</span><span class="hl-reserved">print</span><span class="hl-code"> </span><span class="hl-identifier">tinydict</span><span class="hl-code">.</span><span class="hl-identifier">values</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">    </span><span class="hl-comment"># 输出所有值</span></div>
</div>
</div>
<p>输出结果为：</p>
<pre>
This is one
This is two
{'dept': 'sales', 'code': 6734, 'name': 'runoob'}
['dept', 'code', 'name']
['sales', 6734, 'runoob']
</pre>
<br><hr><h2>Python数据类型转换</h2>
<p>有时候，我们需要对数据内置的类型进行转换，数据类型的转换，你只需要将数据类型作为函数名即可。</p>
<p>以下几个内置的函数可以执行数据类型之间的转换。这些函数返回一个新的对象，表示转换的值。</p>
<table class="reference">
<tbody><tr><th>函数</th><th>描述</th></tr>
<tr valign="top">
<td>
<p><a href="python-func-int.html" target="_blank" rel="noopener noreferrer">int(x [,base])</a></p>
</td>
<td>
<p>将x转换为一个整数</p>
</td>
</tr>
<tr valign="top">
<td>
<p><a href="python-func-long.html" target="_blank" rel="noopener noreferrer">long(x [,base] )</a></p>
</td>
<td>
<p>将x转换为一个长整数</p>
</td>
</tr>
<tr valign="top">
<td>
<p><a href="python-func-float.html" target="_blank" rel="noopener noreferrer">float(x)</a></p>
</td>
<td>
<p>将x转换到一个浮点数</p>
</td>
</tr>
<tr valign="top">
<td>
<p><a href="python-func-complex.html" target="_blank" rel="noopener noreferrer">complex(real [,imag])</a></p>
</td>
<td>
<p>创建一个复数</p>
</td>
</tr>
<tr valign="top">
<td>
<p><a href="python-func-str.html" target="_blank" rel="noopener noreferrer">str(x)</a></p>
</td>
<td>
<p>将对象 x 转换为字符串</p>
</td>
</tr>
<tr valign="top">
<td>
<p><a href="python-func-repr.html" target="_blank" rel="noopener noreferrer">repr(x)</a></p>
</td>
<td>
<p>将对象 x 转换为表达式字符串</p>
</td>
</tr>
<tr valign="top">
<td>
<p><a href="python-func-eval.html" target="_blank" rel="noopener noreferrer">eval(str)</a></p>
</td>
<td>
<p>用来计算在字符串中的有效Python表达式,并返回一个对象</p>
</td>
</tr>
<tr valign="top">
<td>
<p><a href="att-tuple-tuple.html" target="_blank" rel="noopener noreferrer">tuple(s)</a></p>
</td>
<td>
<p>将序列 s 转换为一个元组</p>
</td>
</tr>
<tr valign="top">
<td>
<p><a href="att-list-list.html" target="_blank" rel="noopener noreferrer">list(s)</a></p>
</td>
<td>
<p>将序列 s 转换为一个列表</p>
</td>
</tr>
<tr valign="top">
<td>
<p><a href="python-func-set.html" target="_blank" rel="noopener noreferrer">set(s)</a></p>
</td>
<td>
<p>转换为可变集合</p>
</td>
</tr>
<tr valign="top">
<td>
<p><a href="python-func-dict.html" target="_blank" rel="noopener noreferrer">dict(d)</a></p>
</td>
<td>
<p>创建一个字典。d 必须是一个序列 (key,value)元组。</p>
</td>
</tr>
<tr valign="top">
<td>
<p><a href="python-func-frozenset.html" target="_blank" rel="noopener noreferrer">frozenset(s)</a></p>
</td>
<td>
<p>转换为不可变集合</p>
</td>
</tr>
<tr valign="top">
<td>
<p><a href="python-func-chr.html" target="_blank" rel="noopener noreferrer">chr(x)</a></p>
</td>
<td>
<p>  将一个整数转换为一个字符</p>
</td>
</tr>
<tr valign="top">
<td>
<p><a href="python-func-unichr.html" target="_blank" rel="noopener noreferrer">unichr(x)</a></p>
</td>
<td>
<p>将一个整数转换为Unicode字符</p>
</td>
</tr>
<tr valign="top">
<td>
<p><a href="python-func-ord.html" target="_blank" rel="noopener noreferrer">ord(x)</a></p>
</td>
<td>
<p> 将一个字符转换为它的整数值</p>
</td>
</tr>
<tr valign="top">
<td>
<p><a href="python-func-hex.html" target="_blank" rel="noopener noreferrer">hex(x)</a></p>
</td>
<td>
<p>  将一个整数转换为一个十六进制字符串</p>
</td>
</tr>
<tr valign="top">
<td>
<p><a href="python-func-oct.html" target="_blank" rel="noopener noreferrer">oct(x)</a></p>
</td>
<td>
<p> 将一个整数转换为一个八进制字符串</p>
</td>
</tr>
</tbody></table>			<!-- 其他扩展 -->
						
			</div>
			
		</div>
		
		<div class="previous-next-links">
			<div class="previous-design-link"><i style="font-size:16px;" class="fa fa-arrow-left" aria-hidden="true"></i> <a href="../python/python-basic-syntax.html" rel="prev"> Python 基础语法</a> </div>
			<div class="next-design-link"><a href="../python/python-operators.html" rel="next"> Python 运算符</a> <i style="font-size:16px;" class="fa fa-arrow-right" aria-hidden="true"></i></div>
		</div>
		<!-- 笔记列表 -->
		<style>
.wrapper {
  /*text-transform: uppercase; */
  background: #ececec;
  color: #555;
  cursor: help;
  font-family: "Gill Sans", Impact, sans-serif;
  font-size: 20px;
  position: relative;
  text-align: center;
  width: 200px;
  -webkit-transform: translateZ(0); /* webkit flicker fix */
  -webkit-font-smoothing: antialiased; /* webkit text rendering fix */
}

.wrapper .tooltip {
  white-space: nowrap;
  font-size: 14px;
  text-align: left;
  background: #96b97d;
  bottom: 100%;
  color: #fff;
  display: block;
  left: -25px;
  margin-bottom: 15px;
  opacity: 0;
  padding: 14px;
  pointer-events: none;
  position: absolute;
  
  -webkit-transform: translateY(10px);
     -moz-transform: translateY(10px);
      -ms-transform: translateY(10px);
       -o-transform: translateY(10px);
          transform: translateY(10px);
  -webkit-transition: all .25s ease-out;
     -moz-transition: all .25s ease-out;
      -ms-transition: all .25s ease-out;
       -o-transition: all .25s ease-out;
          transition: all .25s ease-out;
  -webkit-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
     -moz-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
      -ms-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
       -o-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
          box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
}
.tooltip a {
	color:#fff;
}
/* This bridges the gap so you can mouse into the tooltip without it disappearing */
.wrapper .tooltip:before {
  bottom: -20px;
  content: " ";
  display: block;
  height: 20px;
  left: 0;
  position: absolute;
  width: 100%;
}  

/* CSS Triangles - see Trevor's post */
.wrapper .tooltip:after {
  border-left: solid transparent 10px;
  border-right: solid transparent 10px;
  border-top: solid #96b97d 10px;
  bottom: -10px;
  content: " ";
  height: 0;
  left: 20%;
  margin-left: -13px;
  position: absolute;
  width: 0;
}
.wrapper .tooltip1 {
	margin-left: 50px;
	padding-top: 0px;
}
/*
.wrapper:hover .tooltip {
  opacity: 1;
  pointer-events: auto;
  -webkit-transform: translateY(0px);
     -moz-transform: translateY(0px);
      -ms-transform: translateY(0px);
       -o-transform: translateY(0px);
          transform: translateY(0px);
}
*/
/* IE can just show/hide with no transition */
.lte8 .wrapper .tooltip {
  display: none;
}

.lte8 .wrapper:hover .tooltip {
  display: block;
}

</style>

<link rel="stylesheet" href="../0/upvotejs.css">
<script src=""></script>
<script src=""></script>
<div class="title" id="comments">
	<h2 class="">
    <div class="altblock">
				<i style="font-size:28px;margin-top: 8px;" class="fa fa-plus-square" aria-hidden="true"></i>
		    </div>
    <span class="mw-headline" id="qa_headline">9  篇笔记</span>
	<span class="mw-headline" id="user_add_note" style="float:right;line-height: 62px;padding-right: 14px;"><i class="fa fa-pencil-square-o" aria-hidden="true"></i>  写笔记</span>
    </h2>
</div>

<div id="postcomments"  style="display:none;" >
	<ol class="commentlist">
		<li class="comment even thread-even depth-1" id="comment-1240"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;赵琪</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;169***3273@qq.com</p></div><div id="runoobvote-id-1240" data-commid = "1240" class="upvotejs"><a class="upvote"></a> <span class="count">197</span></div></div><div class="comt-main" id="div-comment-1240"><p>变量赋值简单粗暴不需要声明类型, 灵活多变,非常好用。</p><p>
数字数据类是不可改变的数据类型，改变数字数据类型会分配一个新的对象。</p><p>
字符串的操作有基本的功能不需要再自己进行拼接遍历的操作。</p><p>
列表用 "[ ]" 标识类似 C 语言中的数组。</p><p>
元组用 "( )" 标识。内部元素用逗号隔开。但是元组不能二次赋值，相当于只读列表。</p><p>
字典用 "{ }" 标识。字典由索引  key 和它对应的值 value 组成。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">赵琪</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;赵琪</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;169***3273@qq.com</p></div></span>6年前 (2017-03-07)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-1410"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;唐</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;454***373@qq.com</p></div><div id="runoobvote-id-1410" data-commid = "1410" class="upvotejs"><a class="upvote"></a> <span class="count">109</span></div></div><div class="comt-main" id="div-comment-1410"><p>变量赋值
</p><pre>
a = 1
b = "god"
</pre><p>
字符串赋值
</p><pre>
str = 'this is string 1'
</pre><p>
列表串赋值
</p><pre>
list = ['this', 'is', 'list', 2]
</pre><p>
元组赋值
</p><pre>
tuple = ('this', 'is', 'tuple', 3)
</pre><p>
字典赋值</p>
<pre>
dict = {1:'this', 2:'is', 3:'dictionary', 4:4}</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">唐</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;唐</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;454***373@qq.com</p></div></span>6年前 (2017-03-10)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-1424"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;tuister</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;tui***r@foxmail.com</p></div><div id="runoobvote-id-1424" data-commid = "1424" class="upvotejs"><a class="upvote"></a> <span class="count">137</span></div></div><div class="comt-main" id="div-comment-1424"><p>python 的所有数据类型都是类,可以通过 type() 查看该变量的数据类型:</p>
<pre>
&gt;&gt;&gt; n=1
&gt;&gt;&gt; type(n)
&lt;type 'int'&gt;
&gt;&gt;&gt; n="runoob"
&gt;&gt;&gt; type(n)
&lt;type 'str'&gt;
&gt;&gt;&gt; 
</pre>
<p>此外还可以用 isinstance 来判断：</p>
<pre>
a = 111
isinstance(a, int)
True
</pre>
<p>
isinstance 和 type 的区别在于：</p>
<pre>
&gt;&gt;&gt; class A:
...     pass
... 
&gt;&gt;&gt; class B(A):
...     pass
... 
&gt;&gt;&gt; isinstance(A(), A)
True
&gt;&gt;&gt; type(A()) == A
False
&gt;&gt;&gt; isinstance(B(), A)
True
&gt;&gt;&gt; type(B()) == A 
False
</pre><p>
区别就是: </p>
<ul><li>
type()不会认为子类是一种父类类型。</li><li>
isinstance()会认为子类是一种父类类型。</li></ul><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">tuister</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;tuister</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;tui***r@foxmail.com</p></div></span>6年前 (2017-03-12)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-11433"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;流浪猴子</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;122***6850@qq.com</p></div><div id="runoobvote-id-11433" data-commid = "11433" class="upvotejs"><a class="upvote"></a> <span class="count">71</span></div></div><div class="comt-main" id="div-comment-11433"><p>数据类型 分为数字型和非数字型。</p><p>数字型包括整型，长整型，浮点型，复数型；</p><p>非数字型包括字符串，列表，元组和字典 ；</p><p>非数字型的共同点：都可以使用切片、链接（+）、重复（*）、取值（a[]）等相关运算;</p><p>非数字型的不同点：</p><p>列表 可以直接赋值，元组不可以赋值，字典按照 <strong>dict[k]=v</strong> 的方式赋值。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">流浪猴子</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;流浪猴子</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;122***6850@qq.com</p></div></span>6年前 (2017-04-27)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-11576"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;python.熊</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;767***386@qq.com</p></div><div id="runoobvote-id-11576" data-commid = "11576" class="upvotejs"><a class="upvote"></a> <span class="count">32</span></div></div><div class="comt-main" id="div-comment-11576"><ol><li>字符串表示方式：str="hello,world"</li><li>列表表示方式：list=['hello',2,3,4,'world']</li><li>元组：tuple=('hello',2,3,4,'world')</li><li>截取方式相同：名称[头下标:尾下标]</li><li>下标是从0开始算起，可以是正数或者负数，下标为空则表示取到头或者尾</li><li>开始截取时，包含了下边界，而截取到最大范围不包括上边界。</li><li>元组不能二次赋值，列表可以</li></ol><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">python.熊</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;python.熊</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;767***386@qq.com</p></div></span>6年前 (2017-05-02)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-12961"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;sunny想学python</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;139***38053@163.com</p></div><div id="runoobvote-id-12961" data-commid = "12961" class="upvotejs"><a class="upvote"></a> <span class="count">18</span></div></div><div class="comt-main" id="div-comment-12961"><p>Python变量类型：</p><p>（1）Numbers</p><p>（2）String</p><p>（3）List &nbsp;[]</p><p>（4）Tuple（元祖）(),相当于只读列表，不可以二次赋值</p><p>（5）dictionary（字典）{}，key值对</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">sunny想学python</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;sunny想学python</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;139***38053@163.com</p></div></span>6年前 (2017-06-14)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-33746"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;gu</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;413***461@qq.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="../w3cnote/python-variable-references-and-copies.html">&nbsp;&nbsp;参考地址</a></p></div><div id="runoobvote-id-33746" data-commid = "33746" class="upvotejs"><a class="upvote"></a> <span class="count">66</span></div></div><div class="comt-main" id="div-comment-33746"><pre>
#!/usr/bin/python
# -*- coding: UTF-8 -*-

a=1
str=[a]
a=2        # 数字类型是不可变数据类型，重新开辟一块内存，把新地址与变量名绑定，并非改变原空间内的值
print (str)</pre>

<p>输出结果不是 <strong>[2]</strong> 是 <strong>[1]</strong>。</p>

<p>这儿涉及到 Python 赋值到底是引用还是拷贝一份的问题，即赋值时是传值还是传址。上面问题是将“a”的值赋给了str出现了上述情况。</p>

<p>具体分析请见 <a href="../w3cnote/python-variable-references-and-copies.html" target="_blank" rel="noopener nofollow">Python 中变量赋值传递时的引用和拷贝</a></p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">gu</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;gu</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;413***461@qq.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="../w3cnote/python-variable-references-and-copies.html">&nbsp;&nbsp;参考地址</a></p></div></span>5年前 (2018-08-08)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-49549"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;643162368</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;643***368@qq.com</p></div><div id="runoobvote-id-49549" data-commid = "49549" class="upvotejs"><a class="upvote"></a> <span class="count">27</span></div></div><div class="comt-main" id="div-comment-49549"><p><strong data-title>str() 与 repr() 的使用区别</strong></p>

<p>1.针对字符串类型的转换，repr() 方法是在外层加引号，这一特性在 eval() 操作时特别有用。</p>

<p>例如：</p>


<pre>&gt;&gt;&gt; s = 'abdcf'
&gt;&gt;&gt; eval('['+','.join([repr(i) for i in s])+']')
['a', 'b', 'd', 'c', 'f']</pre>

<p>
<strong>错误原因：</strong> 当 <span class="marked">','.join([str(i) for i in s])</span> 拼接后的结果 'a,b,d,c,f' 只有一层引号，eval 执行时会去掉这层引号， 就成了a,b,d,c,f，解释器就会当做变量对待，但是并没有定义这样的变量，所以报 NameError 错误</p>

<p>2.控制台输出时默认调用 repr()，print() 输出调用 str。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="../note/49549">643162368</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;643162368</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;643***368@qq.com</p></div></span>3年前 (2019-12-25)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-56840"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;clear_rain</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;cle***rain@163.com</p></div><div id="runoobvote-id-56840" data-commid = "56840" class="upvotejs"><a class="upvote"></a> <span class="count">28</span></div></div><div class="comt-main" id="div-comment-56840"><p>不推荐使用 <strong>type(instance) == class</strong> 来判断数据类型： </p>

<pre>class A:
    pass

class C(A):
    pass

a = A()
c = C()

print type(a) == A,
print type(c) == C,
print type(A()) == A,
print type(C()) == C

# False False False False

print a.__class__ is A,
print c.__class__ is A,
print a.__class__ is C,
print c.__class__ is C

# True False False True

print isinstance(a, A),
print isinstance(c, A),
print isinstance(a, C),
print isinstance(c, C)

# True True False True</pre><p>
可以看出 <strong>type(instance) == class</strong> 总是等于 <strong>False</strong>。</p>

<p>而 <span class="marked">instance.__class__ is class</span> 能精确的判断是否是本类。</p>

<p><strong>isinstance(instance, class)</strong> 可以判断出实例是否是某类或者其子类。</p>

<p>当然我们也可以使 A 类继承于新式类 <strong>object</strong>：</p>

<pre>class A(object)</pre>
<p>那么新的结果是这样：</p>

<pre>True True True True
True False False True
True True False True</pre>
<p>区别在于 type(instance) == class 可以正常工作了，但是我们为什么不用 isinstance 或者 __class__ is 这种更快的方式呢，地址比较总是快于值比较。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">clear_rain</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;clear_rain</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;cle***rain@163.com</p></div></span>3年前 (2020-09-07)</div></div></li><!-- #comment-## -->
	</ol>
	<div class="pagenav">
			</div>
</div>
<div id="respond" class="no_webshot"> 
		<div class="comment-signarea" style="display:none; padding: 20px 20px;"> 
	<h3 class="text-muted" id="share_code" style="color: #799961;"><i class="fa fa-pencil-square-o" aria-hidden="true"></i> 点我分享笔记</h3>
	<!--
	<p style="font-size:14px;">笔记需要是本篇文章的内容扩展！</p><br>
	<p style="font-size:12px;"><a href="../tougao" target="_blank">文章投稿，可点击这里</a></p>
	<p style="font-size:14px;"><a href="../w3cnote/runoob-user-test-intro.html#invite" target="_blank">注册邀请码获取方式</a></p>
		<h3 class="text-muted"><i class="fa fa-info-circle" aria-hidden="true"></i> 分享笔记前必须<a href="javascript:;" class="runoob-pop">登录</a>！</h3>
		<p><a href="../w3cnote/runoob-user-test-intro.html#invite" target="_blank">注册邀请码获取方式</a></p>-->
	</div>
		
	<form action="/wp-content/themes/runoob/option/addnote.php" method="post" id="commentform" style="display:none;">
		<div class="comt">
			<div class="comt-title">
				<i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i>				<p><a id="cancel-comment-reply-link" href="javascript:;">取消</a></p>
			</div>
			<div class="comt-box">
			<div id="mded"></div>
			
				<div class="comt-ctrl">
					<div class="comt-tips"><input type='hidden' name='comment_post_ID' value='4013' id='comment_post_ID' />
<input type='hidden' name='comment_parent' id='comment_parent' value='0' />
</div>
					<button type="submit" name="submit" id="submit" tabindex="5"><i class="fa fa-pencil" aria-hidden="true"></i> 分享笔记</button>
				</div>
			</div>
		
				
					<div class="comt-comterinfo"> 
						<ul id="comment-author-info">
							<li class="form-inline"><label class="hide" for="author">昵称</label><input class="ipt" type="text" name="author" id="author" value="" tabindex="2" placeholder="昵称"><span class="text-muted">昵称 (必填)</span></li>
							<li class="form-inline"><label class="hide" for="email">邮箱</label><input class="ipt" type="text" name="email" id="email" value="" tabindex="3" placeholder="邮箱"><span class="text-muted">邮箱 (必填)</span></li>
							<li class="form-inline"><label class="hide" for="url">引用地址</label><input class="ipt" type="text" name="url" id="url" value="" tabindex="4" placeholder="引用地址"><span class="text-muted">引用地址</span></li>
						</ul>
					</div>
				
			
		</div>

	</form>
	</div>
<script type="text/javascript">
$(function() {
	//初始化编辑器
	
	var editor = new Simditor({
	  textarea: $('#mded'),
	  placeholder: '写笔记...',
	  upload:false,
	 // upload: {url:'/api/comment_upload_file.php',params: null,fileKey: 'upload_file',connectionCount: 1,leaveConfirm: '文件正在上传，您确定离开?'},
	  defaultImage: 'https://www.runoob.com/images/logo.png',
	  codeLanguages: '',
	  autosave: 'editor-content',
	  toolbar: [  'bold','code','ul','ol','image' ]
	});
	editor.on('selectionchanged', function() {
		$(".code-popover").hide();
	});

	// 提交数据
	$("#share_code").click(function() {
		$(".comment-signarea").hide();
		$("#commentform").show();
		
	});
	$("#user_add_note").click(function() {
		$(".comment-signarea").hide();
		$("#commentform").show();
		$('html, body').animate({
       	    scrollTop: $("#respond").offset().top
    	}, 200);
	});

	// 提交笔记
	var commentform=$('#commentform');
	commentform.prepend('<div id="comment-status" style="display:none;" ></div>');
	var statusdiv=$('#comment-status');
	
	commentform.submit(function(e){
		e.preventDefault();
		var noteContent = editor.getValue();
		// console.log(noteContent);
		noteContent = noteContent.replace(/<pre><code>/g,"<pre>");
		noteContent = noteContent.replace(/<\/code><\/pre>/g,"</pre>");
		
		// 系列化表单数据
		var comment_parent = 0;
		var is_user_logged_in = $("#is_user_logged_in").val();
		var comment_post_ID =  4013;
		var _wp_unfiltered_html_comment = $("#_wp_unfiltered_html_comment").val();
		var comment = noteContent;
		var author = $("#author").val();
		var url = $("#url").val();
		var email = $("#email").val();
		if(isBlank(author) && is_user_logged_in==0) {
			statusdiv.html('<p  class="ajax-error">请输入昵称！</p>').show();
		} else if(isBlank(email)  && is_user_logged_in==0) {
			statusdiv.html('<p  class="ajax-error">请输入邮箱！</p>').show();
		} else {
			// var formdata=commentform.serialize() + "&comment=" + noteContent ;
			// 添加状态信息
			statusdiv.html('<p>Processing...</p>').show();
			// 获取表单提交地址
			var formurl=commentform.attr('action');
			
			// 异步提交
			$.ajax({
					type: 'post',
					url: formurl,
					dataType:'json',
					data: {"comment_parent":comment_parent,"comment_post_ID":comment_post_ID, "_wp_unfiltered_html_comment":_wp_unfiltered_html_comment,"comment":comment,"url":url, "email":email,"author":author},
					error: function(XMLHttpRequest, textStatus, errorThrown){
					statusdiv.html('<p class="ajax-error" >数据不完整或表单提交太快了！</p>').show();
				},
				success: function(data, textStatus){
					if(data.errorno=="0") {
						$("#submit").prop('disabled', true);
						statusdiv.html('<p class="ajax-success" >笔记已提交审核，感谢分享笔记！</p>').show();
						alert('笔记已提交审核，感谢分享笔记！');
					}else{
						statusdiv.html('<p class="ajax-error" >'+data.msg+'</p>').show();
					}
					commentform.find('textarea[name=comment]').val('');
				}
			});
			setTimeout(function(){
		        $("#submit").prop('disabled', false);
		    }, 10*1000);
		}
		return false;

	});
	$(".comt-author").click(function() {
		href = $(this).children("a").attr("href");
		if(href.indexOf("/note/")!=-1) {
			var win = window.open(href, '_blank');
  			win.focus();
		}
	});
	$(".comt-meta span").hover(function(){
		$(this).children(".tooltip").css({ "opacity": 1, "pointer-events": "auto"});
	},function(){
		$(this).children(".tooltip").removeAttr("style");
	});
	/*
	$(".wrapper i").hover(function(){
		$(this).siblings(".tooltip").css({ "opacity": 1, "pointer-events": "auto"});
	},function(){
		$(this).siblings(".tooltip").css({ "opacity": 0, "pointer-events": "auto"});
	});
	*/
	//Upvote.create('runoobvote-id', {callback: vote_callback});
	var ajaxurl = 'https://www.runoob.com/wp-admin/admin-ajax.php';
	var callback = function(data) {
		//console.log($('#runoobvote-id').upvote('upvoted'));
		//console.log($('#runoobvote-id').upvote('downvoted'));
		//console.log(data);
		_vote_action = data.action;
		id_arr = data.id.split('-');
		um_id= id_arr[2];
		//console.log(um_id);
		
		var re = /^[1-9]+/;
		if (re.test(um_id)) { 
			var ajax_data = {
				_vote_action: _vote_action,
				action: "pinglun_zan",
				um_id: um_id,
				um_action: "ding"
			};
			//console.log(ajax_data);
			$.post(ajaxurl,ajax_data,function(status){
				//if(status.vote_num>999) {
				//	_voteHtml = '<span style="display: block; text-align: center;font-size: 20px; color: #6a737c; margin: 8px 0;">'+kFormatter(status.vote_num) +'</span>';
				//	$("#runoobvote-id-" + um_id + " .count").hide().after(_voteHtml);
				//}
				
			});
		}
	};
	if($('#comments').length && $('.upvotejs').length){
		$('.upvotejs').upvote({id: 4013, callback: callback});
	
		$.post(ajaxurl,{"action":"pinglun_zan","postid":4013},function(data){  
			$(data).each(function(key,value) {
				$("#runoobvote-id-" + value.commid + " .upvote").addClass(value.upvotejs_class);
				$("#runoobvote-id-" + value.commid + " .downvote").addClass(value.downvote_class);
				$("#runoobvote-id-" + value.commid + " .count").text(value.upvote_count);
			})
		},'json');
		
	}
	
	
});
function isBlank(str) {
    return (!str || /^\s*$/.test(str));
}
function kFormatter(num) {
	// return num;
    return Math.abs(num) > 999 ? Math.sign(num)*((Math.abs(num)/1000).toFixed(1)) + 'k' : Math.sign(num)*Math.abs(num)
}

</script>

<link rel="stylesheet" href="../0/qa.css?1.44">
<link rel="stylesheet" type="text/css" href="../0/simditor.min.css" />
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
		<div class="sidebar-box ">
				

<style>	
.responsive_ad1 { display:none; }
@media(min-width: 800px) { .responsive_ad1 {  display:block;margin:0 auto;} }
</style>
<div id="ad-336280" >

<script async src=""
     crossorigin="anonymous"></script>
<!-- 移动版 自动调整 -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-5751451760833794"
     data-ad-slot="1691338467"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
		</div>
				</div>
		
	</div>
</div>
	

<!-- 右边栏 -->
<div class="fivecol last right-column">

<style>
.sidebar-tree .double-li {
    width:300px;
}
.sidebar-tree .double-li li {
    width: 44%;
    line-height: 1.5em;
    border-bottom: 1px solid #ccc;
    float: left;
    display: inline;
}
</style>

    
        <div class="sidebar-box re-box re-box-large">
        <div class="sidebar-box recommend-here" style="margin: 0 auto;">
            <a href="javascript:void(0);" style="font-size: 16px; color:#64854c;font-weight:bold;"> <i class="fa fa-list" aria-hidden="true"></i> 分类导航</a>
        </div>
    <div class="sidebar-box sidebar-cate">
        
        <div class="sidebar-tree" >
            <ul><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> HTML / CSS</a><ul class="double-li"><li><a title="HTML 教程" href="../html/html-tutorial.html">HTML 教程</a></li><li><a title="HTML5 教程" href="../html/html5-intro.html">HTML5 教程</a></li><li><a title="CSS 教程" href="../css/css-tutorial.html">CSS 教程</a></li><li><a title="CSS3 教程" href="../css3/css3-tutorial.html">CSS3 教程</a></li><li><a title="Bootstrap3 教程" href="../bootstrap/bootstrap-tutorial.html">Bootstrap3 教程</a></li><li><a title="Bootstrap4 教程" href="../bootstrap4/bootstrap4-tutorial.html">Bootstrap4 教程</a></li><li><a title="Bootstrap5 教程" href="../bootstrap5/bootstrap5-tutorial.html">Bootstrap5 教程</a></li><li><a title="Font Awesome 教程" href="../font-awesome/fontawesome-tutorial.html">Font Awesome 教程</a></li><li><a title="Foundation 教程" href="../foundation/foundation-tutorial.html">Foundation 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> JavaScript</a><ul class="double-li"><li><a title="JavaScript 教程" href="../js/js-tutorial.html">JavaScript 教程</a></li><li><a title="HTML DOM 教程" href="../htmldom/htmldom-tutorial.html">HTML DOM 教程</a></li><li><a title="jQuery 教程" href="../jquery/jquery-tutorial.html">jQuery 教程</a></li><li><a title="AngularJS 教程" href="../angularjs/angularjs-tutorial.html">AngularJS 教程</a></li><li><a title="AngularJS2 教程" href="../angularjs2/angularjs2-tutorial.html">AngularJS2 教程</a></li><li><a title="Vue.js 教程" href="../vue2/vue-tutorial.html">Vue.js 教程</a></li><li><a title="Vue3 教程" href="../vue3/vue3-tutorial.html">Vue3 教程</a></li><li><a title="React 教程" href="../react/react-tutorial.html">React 教程</a></li><li><a title="TypeScript 教程" href="../typescript/ts-tutorial.html">TypeScript 教程</a></li><li><a title="jQuery UI 教程" href="../jqueryui/jqueryui-tutorial.html">jQuery UI 教程</a></li><li><a title="jQuery EasyUI 教程" href="../jeasyui/jqueryeasyui-tutorial.html">jQuery EasyUI 教程</a></li><li><a title="Node.js 教程" href="../nodejs/nodejs-tutorial.html">Node.js 教程</a></li><li><a title="AJAX 教程" href="../ajax/ajax-tutorial.html">AJAX 教程</a></li><li><a title="JSON 教程" href="../json/json-tutorial.html">JSON 教程</a></li><li><a title="Echarts 教程" href="../echarts/echarts-tutorial.html">Echarts 教程</a></li><li><a title="Chart.js 教程" href="../chartjs/chartjs-tutorial.html">Chart.js 教程</a></li><li><a title="Highcharts 教程" href="../highcharts/highcharts-tutorial.html">Highcharts 教程</a></li><li><a title="Google 地图 教程" href="../googleapi/google-maps-basic.html">Google 地图 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 服务端</a><ul class="double-li"><li><a title="Python 教程" href="../python3/python3-tutorial.html">Python 教程</a></li><li><a title="Python2.x 教程" href="../python/python-tutorial.html">Python2.x 教程</a></li><li><a title="Linux 教程" href="../linux/linux-tutorial.html">Linux 教程</a></li><li><a title="Docker 教程" href="../docker/docker-tutorial.html">Docker 教程</a></li><li><a title="Ruby 教程" href="../ruby/ruby-tutorial.html">Ruby 教程</a></li><li><a title="Java 教程" href="../java/java-tutorial.html">Java 教程</a></li><li><a title="C 教程" href="../c/c-tutorial.html">C 教程</a></li><li><a title="C++ 教程" href="../cplusplus/cpp-tutorial.html">C++ 教程</a></li><li><a title="Perl 教程" href="../perl/perl-tutorial.html">Perl 教程</a></li><li><a title="Servlet 教程" href="../servlet/servlet-tutorial.html">Servlet 教程</a></li><li><a title="JSP 教程" href="../jsp/jsp-tutorial.html">JSP 教程</a></li><li><a title="Lua 教程" href="../lua/lua-tutorial.html">Lua 教程</a></li><li><a title="Rust 教程" href="../rust/rust-tutorial.html">Rust 教程</a></li><li><a title="Scala 教程" href="../scala/scala-tutorial.html">Scala 教程</a></li><li><a title="Go 教程" href="../go/go-tutorial.html">Go 教程</a></li><li><a title="PHP 教程" href="../php/php-tutorial.html">PHP 教程</a></li><li><a title="数据结构与算法" href="../data-structures/data-structures-tutorial.html">数据结构与算法</a></li><li><a title="Django 教程" href="../django/django-tutorial.html">Django 教程</a></li><li><a title="Zookeeper 教程" href="../w3cnote/zookeeper-tutorial.html">Zookeeper 教程</a></li><li><a title="设计模式" href="../design-pattern/design-pattern-tutorial.html">设计模式</a></li><li><a title="正则表达式" href="../regexp/regexp-tutorial.html">正则表达式</a></li><li><a title="Maven 教程" href="../maven/maven-tutorial.html">Maven 教程</a></li><li><a title="Verilog 教程" href="../w3cnote/verilog-tutorial.html">Verilog 教程</a></li><li><a title="ASP 教程" href="../asp/asp-tutorial.html">ASP 教程</a></li><li><a title="AppML 教程" href="../appml/appml-tutorial.html">AppML 教程</a></li><li><a title="VBScript 教程" href="../vbscript/vbscript-tutorial.html">VBScript 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 数据库</a><ul class="double-li"><li><a title="SQL 教程" href="../sql/sql-tutorial.html">SQL 教程</a></li><li><a title="MySQL 教程" href="../mysql/mysql-tutorial.html">MySQL 教程</a></li><li><a title="PostgreSQL 教程" href="../postgresql/postgresql-tutorial.html">PostgreSQL 教程</a></li><li><a title="SQLite 教程" href="../sqlite/sqlite-tutorial.html">SQLite 教程</a></li><li><a title="MongoDB 教程" href="../mongodb/mongodb-tutorial.html">MongoDB 教程</a></li><li><a title="Redis 教程" href="../redis/redis-tutorial.html">Redis 教程</a></li><li><a title="Memcached 教程" href="../Memcached/Memcached-tutorial.html">Memcached 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 数据分析</a><ul class="double-li"><li><a title="Python 教程" href="../python3/python3-tutorial.html">Python 教程</a></li><li><a title="NumPy 教程" href="../numpy/numpy-tutorial.html">NumPy 教程</a></li><li><a title="Pandas 教程" href="../pandas/pandas-tutorial.html">Pandas 教程</a></li><li><a title="Matplotlib 教程" href="../matplotlib/matplotlib-tutorial.html">Matplotlib 教程</a></li><li><a title="Scipy 教程" href="../scipy/scipy-tutorial.html">Scipy 教程</a></li><li><a title="R 教程" href="../r/r-tutorial.html">R 教程</a></li><li><a title="Julia 教程" href="../julia/julia-tutorial.html">Julia 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 移动端</a><ul class="double-li"><li><a title="Android 教程" href="../w3cnote/android-tutorial-intro.html">Android 教程</a></li><li><a title="Swift 教程" href="../swift/swift-tutorial.html">Swift 教程</a></li><li><a title="jQuery Mobile 教程" href="../jquerymobile/jquerymobile-tutorial.html">jQuery Mobile 教程</a></li><li><a title="ionic 教程" href="../ionic/ionic-tutorial.html">ionic 教程</a></li><li><a title="Kotlin 教程" href="../kotlin/kotlin-tutorial.html">Kotlin 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> XML 教程</a><ul class="double-li"><li><a title="XML 教程" href="../xml/xml-tutorial.html">XML 教程</a></li><li><a title="DTD 教程" href="../dtd/dtd-tutorial.html">DTD 教程</a></li><li><a title="XML DOM 教程" href="../dom/dom-tutorial.html">XML DOM 教程</a></li><li><a title="XSLT 教程" href="../xsl/xsl-tutorial.html">XSLT 教程</a></li><li><a title="XPath 教程" href="../xpath/xpath-tutorial.html">XPath 教程</a></li><li><a title="XQuery 教程" href="../xquery/xquery-tutorial.html">XQuery 教程</a></li><li><a title="XLink 教程" href="../xlink/xlink-tutorial.html">XLink 教程</a></li><li><a title="XPointer 教程" href="../xlink/xlink-tutorial.html">XPointer 教程</a></li><li><a title="XML Schema 教程" href="../schema/schema-tutorial.html">XML Schema 教程</a></li><li><a title="XSL-FO 教程" href="../xslfo/xslfo-tutorial.html">XSL-FO 教程</a></li><li><a title="SVG 教程" href="../svg/svg-tutorial.html">SVG 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> ASP.NET</a><ul class="double-li"><li><a title="ASP.NET 教程" href="../aspnet/aspnet-tutorial.html">ASP.NET 教程</a></li><li><a title="C# 教程" href="../csharp/csharp-tutorial.html">C# 教程</a></li><li><a title="Web Pages 教程" href="../aspnet/webpages-intro.html">Web Pages 教程</a></li><li><a title="Razor 教程" href="../aspnet/razor-intro.html">Razor 教程</a></li><li><a title="MVC 教程" href="../aspnet/mvc-intro.html">MVC 教程</a></li><li><a title="Web Forms 教程" href="../aspnet/aspnet-intro.html">Web Forms 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> Web Service</a><ul class="double-li"><li><a title="Web Service 教程" href="../webservices/webservices-tutorial.html">Web Service 教程</a></li><li><a title="WSDL 教程" href="../wsdl/wsdl-tutorial.html">WSDL 教程</a></li><li><a title="SOAP 教程" href="../soap/soap-tutorial.html">SOAP 教程</a></li><li><a title="RSS 教程" href="../rss/rss-tutorial.html">RSS 教程</a></li><li><a title="RDF 教程" href="../rdf/rdf-tutorial.html">RDF 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 开发工具</a><ul class="double-li"><li><a title="Eclipse 教程" href="../eclipse/eclipse-tutorial.html">Eclipse 教程</a></li><li><a title="Git 教程" href="../git/git-tutorial.html">Git 教程</a></li><li><a title="Svn 教程" href="../svn/svn-tutorial.html">Svn 教程</a></li><li><a title="Markdown 教程" href="../markdown/md-tutorial.html">Markdown 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 网站建设</a><ul class="double-li"><li><a title="HTTP 教程" href="../http/http-tutorial.html">HTTP 教程</a></li><li><a title="网站建设指南" href="../web/web-buildingprimer.html">网站建设指南</a></li><li><a title="浏览器信息" href="../browsers/browser-information.html">浏览器信息</a></li><li><a title="网站主机教程" href="../hosting/hosting-tutorial.html">网站主机教程</a></li><li><a title="TCP/IP 教程" href="../tcpip/tcpip-tutorial.html">TCP/IP 教程</a></li><li><a title="W3C 教程" href="../w3c/w3c-tutorial.html">W3C 教程</a></li><li><a title="网站品质" href="../quality/quality-tutorial.html">网站品质</a></li></ul></li></ul>            </div>
    
    </div>
    </div>
    <br>
    
    <div class="sidebar-box re-box re-box-large">
        <div class="sidebar-box recommend-here">
            <a href="javascript:void(0);">Advertisement</a>
        </div>
        <div class="re-600160" id="sidebar-right-re">
                <script async src=""></script>
        <!-- 侧栏1 -->
        <ins class="adsbygoogle"
             style="display:inline-block;width:160px;height:600px"
             data-ad-client="ca-pub-5751451760833794"
             data-ad-slot="4106274865"></ins>
        <script>
        (adsbygoogle = window.adsbygoogle || []).push({});
        </script>
                </div>
    </div>
</div></div>

</div>

<script>
var aid = 4013;
function coll() {
	$.post( '/wp-content/themes/runoob/option/user/userinfo.php', {aid:aid, action:"collarticle", opt:'add'},function( data ) {
		if(data.error==0) {
			$("#content").find("h1:first").find("a").attr("href","javascript:void(0);");
			$("#content").find("h1:first").find("img").attr("src","http://www.runoob.com/wp-content/themes/runoob/assets/img/coll2.png").css({width:32+"px",height:32+"px"});
		}
		alert(data.msg);
	},'json');
}
</script>


<!-- 反馈对话框开始 -->
<script src=""></script>
<link rel="stylesheet" href="../0/feedback.css?1.0" />
<script type="text/javascript">
$.feedback({
    ajaxURL: '/feedback/runoob_feedback.php',
	html2canvasURL: '/wp-content/themes/runoob/assets/feedback/stable/2.0/html2canvas.js',
	onClose: function () {
         window.location.reload();
    }
});
</script>
<!-- 反馈对话框结束 -->
<button class="feedback-btn feedback-btn-gray">反馈/建议</button>
<!-- 底部 -->
<div id="footer" class="mar-t50">
   <div class="runoob-block">
    <div class="runoob cf">
     <dl>
      <dt>
       在线实例
      </dt>
      <dd>
       &middot;<a target="_blank" href="../html/html-examples.html">HTML 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../css/css-examples.html">CSS 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../js/js-examples.html">JavaScript 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../ajx/ajax-examples.html">Ajax 实例</a>
      </dd>
       <dd>
       &middot;<a target="_blank" href="../jquery/jquery-examples.html">jQuery 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../xml/xml-examples.html">XML 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../java/java-examples.html">Java 实例</a>
      </dd>
     
     </dl>
     <dl>
      <dt>
      字符集&工具
      </dt>
      <dd>
       &middot; <a target="_blank" href="../charsets/html-charsets.html">HTML 字符集设置</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="../tags/html-ascii.html">HTML ASCII 字符集</a>
      </dd>
     <dd>
       &middot; <a target="_blank" href="https://c.runoob.com/front-end/6939/">JS 混淆/加密</a>
      </dd> 
      <dd>
       &middot; <a target="_blank" href="https://c.runoob.com/front-end/6232/">PNG/JPEG 图片压缩</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="../tags/html-colorpicker.html">HTML 拾色器</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="..//c.runoob.com/front-end/53">JSON 格式化工具</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="..//c.runoob.com/front-end/6680/">随机数生成器</a>
      </dd>
     </dl>
     <dl>
      <dt>
       最新更新
      </dt>
                   <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imread.html" title="Matplotlib imread() 方法">Matplotlib imre...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imsave.html" title="Matplotlib imsave() 方法">Matplotlib imsa...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imshow.html" title="Matplotlib imshow() 方法">Matplotlib imsh...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-hist.html" title="Matplotlib 直方图">Matplotlib 直方图</a>
      </dd>
              <dd>
       &middot;
      <a href="../python3/python-func-object.html" title="Python object() 函数">Python object()...</a>
      </dd>
              <dd>
       &middot;
      <a href="../python3/python-ai-draw.html" title="Python AI 绘画">Python AI 绘画</a>
      </dd>
              <dd>
       &middot;
      <a href="../w3cnote/cursor-editor.html" title="神辅助 Cursor 编辑器，加入 GPT-4 让编码更轻松！">神辅助 Cursor ...</a>
      </dd>
             </dl>
     <dl>
      <dt>
       站点信息
      </dt>
      <dd>
       &middot;
       <a target="_blank" href="mailto:admin@runoob.com" rel="external nofollow">意见反馈</a>
       </dd>
      <dd>
       &middot;
      <a target="_blank" href="../disclaimer">免责声明</a>
       </dd>
      <dd>
       &middot;
       <a target="_blank" href="../aboutus">关于我们</a>
       </dd>
      <dd>
       &middot;
      <a target="_blank" href="../archives">文章归档</a>
      </dd>
    
     </dl>
    
     <div class="search-share">
      <div class="app-download">
        <div>
         <strong>关注微信</strong>
        </div>
      </div>
      <div class="share">
      <img width="128" height="128" src="/wp-content/themes/runoob/assets/images/qrcode.png" />
       </div>
     </div>
     
    </div>
   </div>
   <div class="w-1000 copyright">
     Copyright &copy; 2013-2023    <strong><a href="../" target="_blank">菜鸟教程</a></strong>&nbsp;
    <strong><a href="../" target="_blank">runoob.com</a></strong> All Rights Reserved. 备案号：<a target="_blank" rel="nofollow" href="https://beian.miit.gov.cn/">闽ICP备15012807号-1</a>
   </div>
  </div>
  <div class="fixed-btn">
    <a class="go-top" href="javascript:void(0)" title="返回顶部"> <i class="fa fa-angle-up"></i></a>
    <a class="qrcode"  href="javascript:void(0)" title="关注我们"><i class="fa fa-qrcode"></i></a>
    <a class="writer" style="display:none" href="javascript:void(0)"   title="标记/收藏"><i class="fa fa-star" aria-hidden="true"></i></a>
    <!-- qrcode modal -->
    <div id="bottom-qrcode" class="modal panel-modal hide fade in">
      <h4>微信关注</h4>
      <div class="panel-body"><img alt="微信关注" width="128" height="128" src="/wp-content/themes/runoob/assets/images/qrcode.png"></div> 
    </div>
  </div>

 <div style="display:none;">
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-84264393-2"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-84264393-2');
</script>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?3eec0b7da6548cf07db3bc477ea905ee";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

</div>
<script>
window.jsui={
    www: 'https://www.runoob.com',
    uri: 'https://www.runoob.com/wp-content/themes/runoob'
};
</script>

<script src=""></script>
<script src=""></script>

</body>
</html>